Array.prototype.lFilter = function (callback, thisArg) {
  if (typeof callback !== 'function') {
    throw new TypeError(`${callback} must be a function`);
  }

  const array = this;
  const resArr = new Array();
  let n = 0;
  for (let i = 0; i < array.length; i++) {
    if (array.hasOwnProperty(i)) {
      const flag = callback.call(thisArg, array[i], i, array);
      if (flag) {
        resArr[n] = array[i];
        n++;
      }
    }
  }
  return resArr;
};

const arr = [1, 2, 3, 4].lFilter((x) => x % 2 === 0); // 返回 [2, 4]

console.log(arr);

const calculator = {
  base: 2,
  select: function (numbers) {
    return numbers.lFilter((item) => item % this.base === 0, this);
  },
};
console.log(calculator.select([1, 2, 3, 4]));
